package com.onlyphoto.onlymall.mvp.view.binder

import android.content.Intent
import android.graphics.Paint
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView

import com.onlyphoto.onlymall.R
import com.onlyphoto.onlymall.api.Urls
import com.onlyphoto.onlymall.bean.response.ArticleBean
import com.onlyphoto.onlymall.mvp.view.activity.WebViewActivity

import me.drakeet.multitype.ItemViewBinder

/**
 * Created by gaochujia on 2019-07-09.
 */
class FaqBinder : ItemViewBinder<ArticleBean, FaqBinder.ViewHolder>() {

    override fun onCreateViewHolder(inflater: LayoutInflater, parent: ViewGroup): ViewHolder {
        val root = inflater.inflate(R.layout.item_faq, parent, false)
        return ViewHolder(root)
    }

    override fun onBindViewHolder(viewHolder: ViewHolder, bean: ArticleBean) {
        viewHolder.update(bean)
    }

    class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

        var title: TextView? = null

        init {
            title = itemView.findViewById(R.id.faq_title)
        }

        fun update(bean: ArticleBean) {
            title?.text = bean.title
            title?.paint?.flags = Paint.UNDERLINE_TEXT_FLAG //下划线
            title?.paint?.isAntiAlias = true                //抗锯齿
            title?.setOnClickListener{
                itemView.context?.startActivity(Intent(itemView.context, WebViewActivity::class.java)
                        .putExtra("url", Urls.RAIDERS + bean.id))
            }
        }
    }
}
